package Binary_tree;

public class Code02_UniqueBST {

    public static int numTrees(int n){
        if (n < 2){
            return 1;
        }
        int[] dp = new int[n + 1];
        dp[0] = 1;
        for (int i = 1; i < n + 1; i++){ // 节点个数为i的时候
            for (int j = 1; j < i + 1; j++){ // 左侧节点个数为j-1，右侧结点个数为i-j
                dp[i] += dp[j - 1] * dp[i - j];
            }
        }
        return dp[n];
    }

    public static void main(String[] args){
        int n = 4;
        System.out.println(numTrees(n));
    }
}
